<?php

namespace app\admin\controller;

use app\admin\service\BannerService;

class BannerController extends CommonController
{
    public function initialize()
    {
//        $this->noCheckTokenAction = ["getbannerlist", "getconfig"];
        parent::initialize();
    }

    // 获取banner的分页列表
    public function getBannerList(){
        if($this->returnData["code"] !== 0){
            return $this->return_result($this->returnData);
        }
        $service = $this->app->invokeClass(BannerService::class, [$this->returnData, $this->params]);
        $this->returnData = $service->getList();
        return $this->return_result($this->returnData);
    }

    // 添加banner
    public function toAddBanner(){
        if($this->returnData["code"] !== 0){
            return $this->return_result($this->returnData);
        }
        $service = $this->app->invokeClass(BannerService::class, [$this->returnData, $this->params]);
        $this->returnData = $service->toAdd();
        return $this->return_result($this->returnData);
    }

    // 更新banner
    public function toUpdateBanner(){
        if($this->returnData["code"] !== 0){
            return $this->return_result($this->returnData);
        }
        $service = $this->app->invokeClass(BannerService::class, [$this->returnData, $this->params]);
        $this->returnData = $service->toUpdate();
        return $this->return_result($this->returnData);
    }

    // banner的详细内容
    public function getBannerDetail(){
        if($this->returnData["code"] !== 0){
            return $this->return_result($this->returnData);
        }
        $service = $this->app->invokeClass(BannerService::class, [$this->returnData, $this->params]);
        $this->returnData = $service->getDetail();
        return $this->return_result($this->returnData);
    }

    // 修改状态
    public function toChangeStatusBanner(){
        if($this->returnData["code"] !== 0){
            return $this->return_result($this->returnData);
        }
        $service = $this->app->invokeClass(BannerService::class, [$this->returnData, $this->params]);
        $this->returnData = $service->toChangeStatus();
        return $this->return_result($this->returnData);
    }

    // 删除banner
    public function toDelBanner(){
        if($this->returnData["code"] !== 0){
            return $this->return_result($this->returnData);
        }
        $service = $this->app->invokeClass(BannerService::class, [$this->returnData, $this->params]);
        $this->returnData = $service->toDel();
        return $this->return_result($this->returnData);
    }

}